package com.atguigui.leetcode1;

/**
 * 2315.统计星号
 * Project: leetcode
 * Package: com.atguigui.leetcode1
 * Version: 1.0
 * <p>
 * Created by WJX on 2023/1/29 8:48
 */
public class P2315CountAsterisks {
    public static void main(String[] args) {
        Solution solution = new P2315CountAsterisks().new Solution();
        // TO TEST
    }

    class Solution {
        public int countAsterisks(String s) {

            int ans = 0;

            if (!s.contains("|")) {
                for (int i = 0; i < s.length(); i++) {
                    char c = s.charAt(i);
                    if (c == 42) {
                        ans++;
                    }
                }

                return ans;
            }

            boolean d = false;

            for (int i = 0; i < s.length(); i++) {
                char c = s.charAt(i);
                if (c == 124 && d == false) {
                    d = true;
                } else if (c == 124 && d == true) {
                    d = false;
                }

                if (!d && c == 42) {
                    ans++;
                }
            }


            return ans;
        }
    }
}
